﻿
@{
    Layout = null;
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>产品零件及工序</title>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css"  />
    <link href="~/Content/bootstrap-table.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/style.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/alertify.min.css"  rel="stylesheet" type="text/css" />
    <style>
        #box_add2 { width:420px; padding-bottom:25px; display:none; border:1px solid #ccc; position:fixed; top:50%; left:50%; margin-top:-200px;margin-left:-220px ;background:#fff; box-shadow:0 0 10px #ddd; z-index:99;}
        #box_add2 h2 { position:relative;border-bottom: 1px dotted #e9e9e9;background: #fdfdfd;padding-left:20px; line-height:40px; font-weight:normal; font-size:16px; margin-bottom:25px;}
        #box_add2 h2 span { position:absolute;  height:24px; display:block; line-height:25px; top:8px; right:10px; font-size:24px; cursor:pointer;}
        #box_add2 h2 span:hover { color:#ff0000;} 
        #box_add2 div { height:30px; margin-top:10px;}
        #box_add2 div  select{ width: 250px; float: left; height: 28px;}
        #box_add2 span{ line-height:30px; float:left; display:block; width:115px; text-align:right; padding-right:10px;}
        #box_add2 div input{ width:250px; float:left; line-height:28px; height:28px; border:1px solid #ccc; text-indent:10px;    -moz-box-shadow: 2px 2px 5px #e6e6e6 inset;
            -webkit-box-shadow: 2px 2px 5px #e6e6e6 inset;
            box-shadow: 2px 2px 5px #e6e6e6 inset;
            background: #fafafa;}
        #box_add2 div a{ display:inline-block; width:40px; line-height:28px; border:1px solid #ccc;    margin-left: 8px; text-align:center; cursor:pointer;    text-decoration: none;}	
        #box_add2 p{ margin-top:20px; text-align:center;}
        #box_add2 p input{ display:inline-block;padding: 0 20px;border: 1px solid #ddd; margin:0 10px; cursor:pointer; line-height: 30px; height:30px; font-size: 16px;border-radius: 5px;}

    </style>
</head>

<body>
    <div class="pro_r">
        <div class="pro_top table1">
            <h3><span>零件名称</span></h3>
            <table class="part_table"></table>
            <p><a id="add">添加零件</a><a id="edit">修改零件</a><a id="del">删除零件</a></p>
        </div>
        <div class="pro_bottom table1">
            <h3><span>工序名称</span></h3>
            <table class="gx_table"></table>
            <p><a id="add_1">添加工艺</a><a id="edit_1" href="javascript:;">修改工艺</a><a href="javascript:;" id="delete_1">删除工艺</a></p>
        </div>
    </div>

    <!--添加零件-->
    <div id="box_add2" class="div_partadd">
        <h2>添加零件信息<span>×</span></h2>
        <input type="hidden" name="part_id" value="" />
        <div><span>零件编号：</span><input name="sno" data-type="text" required=required maxlength="50" data-error="零件编号不能为空且长度不能超过50个字符！" style="width:200px;" type="text" /><a class="jb" href="javascript:;" onclick="onSelectPartItm();">>></a></div>
        <div><span>零件名称：</span><input name="name" data-type="text" required=required maxlength="50" data-error="零件名称不能为空且长度不能超过50个字符！" type="text" /></div>
        <p><input type="submit" class="jb" value="保存" onclick="onAddPart();" /><input class="jb" type="button" value="返回" /></p>
    </div>

    <div id="box_sel">
        <h2>选择零件<span>×</span></h2>
        <iframe src="/Product/SearchPart" width="100%" height="100%" frameborder="0"></iframe>
    </div>

    <div id="box_sel_1">
        <h2>工序名查询<span>×</span></h2>
        <iframe src="/Product/SearchGy" width="100%" height="100%" frameborder="0"></iframe>
    </div>

    <div id="box_add5">
        <h2>工序编辑<span>×</span></h2>
        <input type="hidden" value="" name="pp_id" />
        <input type="hidden" value="" name="part_id"/>
        <div><span>零件编号：</span><input type="text" name="Sno" readonly required data-type="text" maxlength="50" data-error="零件编号不能为空且长度不能超过50个字符！" /></div>
        <div><span>零件名称：</span><input type="text" name="Name" readonly required data-type="text" maxlength="50" data-error="零件名称不能为空且长度不能超过50个字符！"  /></div>
        <div><span>工序编号：</span><input type="text" name="GxSno" required data-type="text" maxlength="50" data-error="工序编号不能为空且长度不能超过50个字符！"   /></div>
        <div><span>工序名称：</span><select name="gx_id"><option value="0">请选择</option></select></div>
        <div><span>工序内容：</span><input type="hidden" name="gy_id"><input name="gy_name" type="text" style="width:377px;" required data-type="text" maxlenght="50" data-error="工序内容不能为空且长度不能超过50个字符！" /><a class="jb">>></a></div>
        <div><span>准备工时：</span><input type="text" name="prepare_time"  data-type="number" data-error="准备工时不能为空且必须为数字！" /></div>
        <div><span>单件工时：</span><input type="text" name="single_time"  data-type="number" data-error="单件工时不能为空且必须为数字！"  /></div>
        <div><span>热重(%)：</span><input type="text"  name="hot_percent"  data-type="number" data-error="热重不能为空且必须为数字！" /></div>
        <div><span>操作员工：</span><select name="employee_id"><option value="0">无</option></select></div>
        <div class="clear"></div>
        <p><input type="submit" class="jb" value="保存" onclick="onSaveGx();" /><input class="jb" type="button" value="返回" /></p>
    </div>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap-table.js"></script>
    <script src="~/Scripts/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script src="~/Scripts/alertify.min.js"></script>
    

    <script>
        var productid = GetQueryString("productid");
        var parentid = GetQueryString("parent_id");
        var pp_id = 0;
        var $table_part = $('table.part_table');
        function InitPartTable(pageIndex, pageSize) {
            if (typeof pageIndex == "object") {
                pageIndex = undefined;
            }
            $table_part.bootstrapTable('destroy');
            $table_part.bootstrapTable({
                method: "post",  //使用get请求到服务器获取数据
                url: "/product/ProductPartlistdata", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: pageSize == null ? 10 : pageSize,  //每页显示的记录数
                pageNumber: pageIndex == null ? 1 : pageIndex, //当前第几页
                pageList: [10, 20, 50, 100, 250],  //记录数可选列表
                search: false,  //是否启用查询
                showColumns: false,  //显示下拉框勾选要显示的列
                showRefresh: false,  //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                sortName: "ID",
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        PageIndex: params.pageNumber,
                        PageSize: params.pageSize,
                        sorter: params.sortName + " " + params.sortOrder,
                        productid: productid,
                        parent_id: parentid
                    };
                    return param;
                },
                columns: [
                    {
                        field: 'sno',
                        title: "零件编号",
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'name',
                        title: '零件名称',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'qty',
                        title: '零件个数',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'weight',
                        align: 'center',
                        title: '净重',
                        valign: 'middle'
                    }
                ],
                onLoadSuccess: function () {
                    $('table.part_table tr:even').find('td').css("background", "#e9f3ff");
                    $('table.part_table tr').click(function () {
                        uncheckAll($table_part);
                        $('table.part_table tr').removeClass("act");
                        $(this).addClass("act");
                        $table_part.bootstrapTable('check', $(this).attr("data-index"));

                    });
                },
                onClickRow: function (row, $element) {
                    pp_id = row["pp_id"];
                    InitGxTable();
                }
            });
        }
        InitPartTable();

        var $gx_table = $('table.gx_table');
        function InitGxTable(pageIndex, pageSize) {
            if (typeof pageIndex == "object") {
                pageIndex = undefined;
            }
            $gx_table.bootstrapTable('destroy');
            $gx_table.bootstrapTable({
                method: "post",  //使用get请求到服务器获取数据
                url: "/product/PartGxlistdata", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: pageSize == null ? 10 : pageSize,  //每页显示的记录数
                pageNumber: pageIndex == null ? 1 : pageIndex, //当前第几页
                pageList: [10, 20, 50, 100, 250],  //记录数可选列表
                search: false,  //是否启用查询
                showColumns: false,  //显示下拉框勾选要显示的列
                showRefresh: false,  //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                sortName: "pg_id",
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        PageIndex: params.pageNumber,
                        PageSize: params.pageSize,
                        sorter: params.sortName + " " + params.sortOrder,
                        productid: productid,
                        pp_id: pp_id
                    };
                    return param;
                },
                columns: [
                    {
                        field: 'gx_name',
                        title: "工序名称",
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'gy_shuyu',
                        title: '工序内容',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'prepare_time',
                        title: '准备工时',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'single_time',
                        align: 'center',
                        title: '单件工时',
                        valign: 'middle'
                    },
                    {
                        field: 'hot_percent',
                        align: 'center',
                        title: '热重(%)',
                        valign: 'middle'
                    },
                    {
                        field: 'employee',
                        align: 'center',
                        title: '操作员工',
                        valign: 'middle'
                    }
                ],
                onLoadSuccess: function () {
                    $('table.gx_table tr:even').find('td').css("background", "#e9f3ff");
                    $('table.gx_table tr').click(function () {
                        uncheckAll($gx_table);
                        $('table.gx_table tr').removeClass("act");
                        $(this).addClass("act");
                        $gx_table.bootstrapTable('check', $(this).attr("data-index"));
                    });
                }
            });
        }
        InitGxTable();
    </script>

    <script>
        var update_id = 0;

        $(function () {
            $("#add,#add_1").click(function () {
                var id = $(this).attr("id");
                if (id == "add") {
                    EmptyForm("#box_add2");
                    $("#box_add2").css("display", "block");
                } else {
                    //验证是否选择零件
                    var selected = $table_part.bootstrapTable("getSelections");
                    if (selected == undefined || selected.length == 0) {
                        alertify.error("未选择需要添加工艺的零件！");
                        return;
                    } else {
                        EmptyForm("#box_add5");
                        $("#box_add5 input[name='pp_id']").val(selected[0].pp_id);
                        $("#box_add5 input[name='part_id']").val(selected[0].part_id);
                        $("#box_add5 input[name='Sno']").val(selected[0].sno);
                        $("#box_add5 input[name='Name']").val(selected[0].name);
                        $("#box_add5").css("display", "block");
                    }
                }
            });
            $('#box_add2,#box_add5').find('p input').eq(1).click(function () {
                $(this).parent().parent().css("display", "none");
            });
            $('#box_add2,#box_add5').find('h2 span').click(function () {
                $(this).parent().parent().css("display", "none");
            });

            $("#edit,#edit_1").click(function () {
                var id = $(this).attr("id");
                if (id == "edit") {
                    var selected = $table_part.bootstrapTable("getSelections");
                    if (selected != undefined && selected.length > 0) {
                        $("#box_add2 input[name='part_id']").val(selected[0].part_id);
                        $("#box_add2 input[name='sno']").val(selected[0].sno);
                        $("#box_add2 input[name='name']").val(selected[0].name);
                        $("#box_add2").css("display", "block");
                    } else {
                        alertify.error("未选择需要修改的零件！");
                    }
                } else if (id == "edit_1") {
                    var selected = $table_gx.bootstrapTable("getSelections");
                    if (selected == undefined || selected.length == 0) {
                        alertify.error("未选择需要编辑的工序！");
                        return;
                    }
                    update_id = selected[0].ID;

                    var data = $table_part.bootstrapTable("getData");
                }
            });

            $("#del,#del_1").click(function () {
                var id = $(this).attr("id");
                if (id == "del") {
                    var selected = $table_part.bootstrapTable("getSelections");
                    if (selected != undefined && selected.length > 0) {
                        alertify.confirm("提示", "确认删除零件【" + selected[0].name + "】", function () {
                            PostApi("/Product/DeleteItem", { product_id: selected[0].product_id, pp_id: selected[0].pp_id }, function (result) {
                                if (result.code == 0) {
                                    alertify.success("删除成功！");
                                    InitPartTable();
                                } else {
                                    alertify.error(result.ErrorMessage);
                                }
                            }, function () {
                                alertify.error("零件删除失败！");
                            });
                        }, function () { });
                    } else {
                        alertify.error("未选择需要删除的零件！");
                    }
                } else if (id == "del_1") {

                }
            });

            $('#box_add4 .mc a').click(function(){
                $('#box_sel').css("display","block");
            });
            $('#box_sel').find('p a').click(function(){
                $('#box_sel').css("display","none");
            });
            $('#box_sel').find('h2 span').click(function(){
                $('#box_sel').css("display","none");
            });

            $('#box_add5 a').click(function(){
                $('#box_sel_1').css("display","block");
            });
            $('#box_sel_1').find('p a').click(function(){
                $('#box_sel_1').css("display","none");
            });
            $('#box_sel_1').find('h2 span').click(function(){
                $('#box_sel_1').css("display","none");
            });
        });
    </script>

    <script>
        $(function () {
            //获取工序
            PostApi("/Gongxu/all", {}, function (result) {
                if (result != null && result.length > 0) {
                    $.each(result, function (index, value) {
                        $("select[name='gx_id']").append($("<option/>", {
                            value: value.ID,
                            text: value.name
                        }));
                    });
                }
            }, function () { });
            //获取员工
            PostApi("/Employee/all", {}, function (result) {
                if (result != null && result.length > 0) {
                    $.each(result, function (index, value) {
                        $("select[name='employee_id']").append($("<option/>", {
                            value: value.id,
                            text: value.name
                        }));
                    });
                }
            }, function () { });
        });

        function GxSelectCallback(data) {
            if (data != null) {
                $("#box_sel_1").css("display", "none");
                $("input[name='gy_id']").val(data.id);
                $("input[name='gy_name']").val(data.gy);
            }
        }

        function CloseSelectGxDiv() {
            $("#box_sel_1").css("display", "none");
        }
    </script>
    <script>
        
        var pp_id = GetQueryString("parent_id");
        var productid = GetQueryString("productid");
        function onSaveGx() {
            if (!ValidateModel("#box_add5", function (error) {
                alertify.error(error);
            })) {
                return;
            };

            var selected = $table_part.bootstrapTable("getSelections");
            if (selected == undefined || selected.length == 0) {
                alertify.error("未选择li");
                return;
            }

            var data = GetFormData("#box_add5");
            data["id"] = update_id;
            data["product_id"] = productid;
            PostApi("/Product/AddGxData", JSON.stringify(data), function (result) {
                if (result.code == 0) {
                    if (update_id == 0) {
                        alertify.success("添加成功!");
                        EmptyForm("#box_add5");
                        
                    } else {
                        alertify.success("修改成功!");
                    }
                } else {
                    alertify.error(result.ErrorMessage);
                }
            }, function () {
                if (update_id == 0) {
                    alertify.error("添加失败!");
                } else {
                    alertify.error("修改失败!");
                }
            }, "application/json");
        }

        

        function onAddPart() {
            if (!ValidateModel("#box_add2", function (error) {
                alertify.error(error);
            })) {
                return;
            };
            var data = GetFormData("#box_add2");

            data["parent_part_id"] = pp_id;
            data["product_id"] = productid;

            PostApi("/Product/AddPart", data, function (result) {
                if (result.code == 0) {
                    EmptyForm("#box_add2");
                    alertify.success("零件添加成功！");
                    InitPartTable();
                } else {
                    alertify.error(result.ErrorMessage);
                }
            }, function () {
                alertify.error("添加零件失败！");
            });
        }
    </script>
</body>
</html>

